package com.gimi.cloud.jimi.manage.service.app.impl;

import com.gimi.cloud.jimi.common.utils.Page;
import com.gimi.cloud.jimi.dao.dao.userInfo.UserAppInformationDao;
import com.gimi.cloud.jimi.dao.myMapper.core.query.QueryParam;
import com.gimi.cloud.jimi.dto.userInfo.UserAppInformationDTO;
import com.gimi.cloud.jimi.manage.service.app.UserAppInformationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAppInformationServiceImpl implements UserAppInformationService {

    @Autowired
    private UserAppInformationDao userAppInformationDao;

    @Override
    public Page<UserAppInformationDTO> getUserAppInformationPage(UserAppInformationDTO param) {
        PageHelper.startPage(param.getCurrentPage(), param.getPageSize());
        String sql = "select * from rd_user_app_information where 1=1 and user_id = :userId";
        QueryParam queryParam = new QueryParam();
        queryParam.setSql(sql);
        queryParam.setParamObject(param);
        List<UserAppInformationDTO> results = userAppInformationDao.getUserAppInfomationListPage(queryParam);
        Page<UserAppInformationDTO> page = new Page<UserAppInformationDTO>(new PageInfo<>(results));
        return page;
    }

    @Override
    public Integer getCountByUser(Integer userId) {
        return userAppInformationDao.getCountByUser(userId);
    }
}
